// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   LableTag.java

package com.vandagroup.common.taglib.html;

import com.vandagroup.common.bean.BaseBean;
import com.vandagroup.common.util.web.WebSelUtil;
import com.vandagroup.common.webapp.ResourceReader;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;
import org.apache.struts.util.ResponseUtils;

public class LableTag extends TagSupport
{

    Object value;
    String name;
    BaseBean basebean;
    boolean single;

    public LableTag()
    {
        value = null;
        name = null;
        basebean = null;
        single = false;
    }

    public int doStartTag()
        throws JspException
    {
        if(value == null)
        {
            ResponseUtils.write(pageContext, "<input type=\"text\" name=\"" + name + "\" value=\"\" readonly style=\"background-color:#D9D9D9\">");
            return super.doStartTag();
        }
        if(single)
        {
            ResponseUtils.write(pageContext, "<input type=\"text\" name=\"" + name + "\" value=\"" + value + "\" readonly style=\"background-color:#D9D9D9\">");
        } else
        {
            value = disValue().toString();
            String type = getType();
            String othertablekey = getOtherTableKey();
            String othertablename = getOtherTableName();
            String one = othertablename.substring(0, 1);
            othertablename = one.toUpperCase() + othertablename.substring(1);
            try
            {
                if(type.equals("0"))
                    ResponseUtils.write(pageContext, (String)value);
                else
                if(type.equals("1"))
                {
                    if(value != null)
                        ResponseUtils.write(pageContext, WebSelUtil.getParaDesc(getItem(), value.toString()));
                } else
                if(type.equals("2"))
                    ResponseUtils.write(pageContext, (String)value);
                else
                if(type.equals("3"))
                {
                    othertablename = one.toUpperCase() + othertablename.substring(1).toLowerCase();
                    ResponseUtils.write(pageContext, "<A HREF=" + othertablename + ".do?task=list&step=list&" + othertablekey.toLowerCase() + "=" + value + ">" + value + "</A>");
                } else
                {
                    ResponseUtils.write(pageContext, (String)value);
                }
            }
            catch(Exception e)
            {
                e.printStackTrace();
                ResponseUtils.write(pageContext, (String)value);
            }
        }
        return super.doStartTag();
    }

    private String getType()
    {
        if(pageContext.getAttribute("tableName") == null)
            return "0";
        String type = ResourceReader.getMessageFromResource(pageContext.getAttribute("tableName") + "." + name + "." + "type");
        if(type == null)
            type = "0";
        return type;
    }

    private String getItem()
    {
        String item = ResourceReader.getMessageFromResource(pageContext.getAttribute("tableName") + "." + name + "." + "item");
        if(item == null)
            item = name.toLowerCase();
        return item;
    }

    private String getOtherTableKey()
    {
        String othertablekey = ResourceReader.getMessageFromResource(pageContext.getAttribute("tableName") + "." + name + "." + "otherTableKey");
        if(othertablekey == null)
            othertablekey = name.toLowerCase();
        return othertablekey;
    }

    private String getOtherTableName()
    {
        String othertablename = ResourceReader.getMessageFromResource(pageContext.getAttribute("tableName") + "." + name + "." + "otherTableName");
        if(othertablename == null)
            othertablename = name.toLowerCase();
        return othertablename;
    }

    private Object disValue()
    {
        String val = value.toString();
        if(basebean != null)
            val = basebean.get(name).toString();
        for(; val.indexOf("<") > 0 || val.indexOf(">") > 0; val = val.replaceAll(">", "&gt;"))
            val = val.replaceAll("<", "&lt;");

        return val;
    }

    public int doEndTag()
        throws JspException
    {
        return super.doEndTag();
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public Object getValue()
    {
        return value;
    }

    public void setValue(Object value)
    {
        this.value = value;
    }

    public boolean isSingle()
    {
        return single;
    }

    public void setSingle(boolean single)
    {
        this.single = single;
    }

    public BaseBean getBasebean()
    {
        return basebean;
    }

    public void setBasebean(BaseBean basebean)
    {
        this.basebean = basebean;
    }
}
